package remote;

import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import metadata.schema.*;

@SuppressWarnings("serial")
public class RemoteMetaDataImpl extends UnicastRemoteObject implements RemoteMetaData {
	private Schema sch;

	public RemoteMetaDataImpl(Schema sch) throws RemoteException {
		this.sch = sch;
	}

	public int getColumnCount() throws RemoteException {
		return sch.fields().size();
	}

	public int getColumnType(int column) throws RemoteException {
		String fldname = sch.fields().get(column - 1);
		String type = sch.type(fldname);
		String ty_key = Schema.parseTypeWord(type);
		if(ty_key.equalsIgnoreCase("int"))
			return java.sql.Types.INTEGER;
		else if(ty_key.equalsIgnoreCase("float"))
			return java.sql.Types.FLOAT;
		else if(ty_key.equalsIgnoreCase("char"))
			return java.sql.Types.CHAR;
		else if(ty_key.equalsIgnoreCase("varchar"))
			return java.sql.Types.VARCHAR;
		else if(ty_key.equalsIgnoreCase("boolean"))
			return java.sql.Types.BOOLEAN;
		else if(ty_key.equalsIgnoreCase("datetime"))
			return java.sql.Types.DATE;
		else if(ty_key.equalsIgnoreCase("decimal"))
			return java.sql.Types.DECIMAL;
		else if(ty_key.equalsIgnoreCase("timestamp"))
			return java.sql.Types.TIMESTAMP;
		else throw new RemoteException("Undefined types.");
	}
}
